package com.xyw.code.platform.webapps.rest;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.api.R;
import com.xyw.code.common.core.constant.SecurityConstant;
import com.xyw.code.common.core.entity.vo.Result;
import com.xyw.code.common.core.exception.BaseException;
import com.xyw.code.platform.common.entity.po.SysRole;
import com.xyw.code.platform.common.entity.po.SysUser;
import com.xyw.code.platform.webapps.service.ISysRoleService;
import com.xyw.code.platform.webapps.service.ISysUserService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * Created with IntelliJ IDEA.
 * User: xuyiwei
 * Date: 2020/5/27
 * Time: 下午2:59
 * Email: 1328312923@qq.com
 * Description: No Description
 **/
@Api(value = "主页模块")
@RestController
public class IndexController {

    @Autowired
    private ISysUserService userService;

    @Autowired
    private ISysRoleService roleService;

    /**
     * 用户详情
     * @return
     */
    @RequestMapping(value = "/info")
    public Result<Map<String,Object>> info(HttpServletRequest request) {
        String userJson = request.getHeader(SecurityConstant.X_CLIENT_TOKEN_USER);

        //得到用户
        SysUser user = userService.getById(JSONObject.parseObject(userJson).getLong("userId"));

        Map<String, Object> map = new HashMap<>();
        List<String> list = new ArrayList<>();
        list.add("ADMIN_ROLE");
        map.put("roles", list);
        map.put("avatar", user.getAvatar());
        map.put("nickName", user.getNickName());
        map.put("name", user.getUsername());
        map.put("phone", user.getPhone());
        map.put("email", user.getEmail());
        map.put("deptName", "deptName");

        map.put("introduction","I am a "+user.getUsername());
        return Result.success(map);
    }
}
